<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <script src="https://cdn.jsdelivr.net/npm/axios/dist/axios.min.js"></script>
    <script>
        function myAxios(options){
            // 设置method默认值为get
            const {url, method = 'get'} = options
        return new Promise((resolve,reject) =>{
                // 1.实例化异步对象
                const xhr = new XMLHttpRequest()
                // 2.设置请求的 地址 和方法
                xhr.open(method, url)
                // 3.注册回调函数 服务器响应内容回来之后触发
                xhr.addEventListener('load', function () {
                    resolve(JSON.parse(xhr.response))
                })
                // 4.发送请求
                xhr.send()
            })
        }
        myAxios({
            url:'http://ajax-api.itheima.net/api/news',
            // method:'get'
        }).then((res) => {
            console.log(res)
        })
    </script>
</body>
</html>